package com.shoppingmall.activity.home;


import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.example.zyh.toolslib.base.BaseActivity;
import com.example.zyh.toolslib.base.BaseFragment;
import com.google.android.material.tabs.TabLayout;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.shoppingmall.R;

import com.shoppingmall.adapter.HomeGoodAdepter;

import com.shoppingmall.fragment.SeachResultGooodFragment;
import com.shoppingmall.fragment.SearchResultShopFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * liangwanbo
 */
public class SearchResultActivity extends BaseActivity {


    @BindView(R.id.bnt_back)
    ImageView bntBack;
    @BindView(R.id.search)
    EditText search;
    @BindView(R.id.re_tob)
    RelativeLayout reTob;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    @BindView(R.id.rl_cancel_collect)
    RelativeLayout rlCancelCollect;

    private HomeGoodAdepter homeGoodAdepter;

    private String[] title = {"商品", "店铺"};
    private List<BaseFragment> fragmentList;
    private int selectPos = 0;

    @Override
    protected int initLayout() {
        return R.layout.activity_search_result;
    }

    @Override
    protected void initView() {
        fragmentList = new ArrayList<>();
        fragmentList.add(new SeachResultGooodFragment());
        fragmentList.add(new SearchResultShopFragment());
        ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
        viewPager.setOffscreenPageLimit(2);
        viewPager.setAdapter(viewPagerAdapter);
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.getTabAt(selectPos).select();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {

    }


    @OnClick({R.id.bnt_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.bnt_back:
                this.finish();
                break;

        }
    }

    private class ViewPagerAdapter extends FragmentPagerAdapter {

        public ViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return title[position];
        }
    }


    public interface OnModifyListener {

        void modify(String type);

    }
}
